package com.zyb.insurance.common;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;

public class HBaseClient {

    private Connection connection;

    private HBaseClient() {
        Configuration config = HBaseConfiguration.create();
        String zkAddress = "192.168.21.179:2181,192.168.21.180:2181,192.168.21.181:2181";
        config.set(HConstants.ZOOKEEPER_QUORUM, zkAddress);
        try {
            this.connection = ConnectionFactory.createConnection(config);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public Connection getConnection() {
        return connection;
    }

    private static class Singleton {

        static HBaseClient instance = new HBaseClient();

    }

    public static HBaseClient getInstance() {
        return Singleton.instance;
    }

}
